<?php

namespace app\index\model;

use think\admin\Model;

/**
 * @name:工序流程记录
 * @author:Sam
 * @date:2024-09-01
*/
class Record extends Model
{
    protected $table = "dc_record";

    public function plan(){
        return $this->belongsTo(Plan::class,'plan_id')->append(['crane']);
    }

    public function process(){
        return $this->belongsTo(Process::class,'process_id');
    }


    
    public function getStatusTextAttr($value,$data){
        $status = [0=>'进行中',1=>'已完成'];
        return $status[$data['status']] ?? '未知状态';
    }

    public function getStartTimeAttr($value){
        return $value ? date('Y-m-d H:i',strtotime($value)) : '';
    }

    public function getEndTimeAttr($value){
        return $value ? date('Y-m-d H:i',strtotime($value)) : '';
    }

    public function getCircleAttr($value,$data){
        return $data['end_time'] ? round((strtotime($data['end_time']) - strtotime($data['start_time'])) / 60) : '---';
    }
}